﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsStoreSampleApp
{
    public static class StringExtensions
    {
        public static bool ContainsRomaji(this string source)
        {
            return GetCharsInRange(source, 0x0020, 0x007E);
        }

        public static bool ContainsKatakana(this string source)
        {
            return GetCharsInRange(source, 0x30A0, 0x30FF);
        }

        public static bool ContainsHiragana(this string source)
        {
            return GetCharsInRange(source, 0x3040, 0x309F);
        }

        public static bool ContainsKanji(this string source)
        {
            return GetCharsInRange(source, 0x4E00, 0x9FBF);
        }

        public static bool StartsWithKanji(this string source)
        {
            return ContainsKanji(source.Substring(0, 1));
        }

        private static bool GetCharsInRange(string source, int min, int max)
        {
            var input = source.ToCharArray();
            return input.Any(e => e >= min && e <= max);
        }
    }
}
